<template>
  <div style="padding-top: 30px">
    <div>
      <!-- <pdf-header :pdfData="searchData"></pdf-header> -->
    </div>
    <div v-for="(item, index) in searchFileData" :key="index">
      <pdf-item class="pdf-item" :pdfData="item"></pdf-item>
    </div>
  </div>
</template>

<script setup lang="ts">
import pdfItem from "./pdfItem.vue";
import pdfHeader from "../../components/pdfHeader.vue";
import { onMounted, ref } from "vue";
import $axios from "@/http";
import { pdfType, templateArrItemType } from "@/type/pdf";
const searchFileData = ref<Array<templateArrItemType>>([]);
const AllFileData = ref<Array<pdfType>>([]);
onMounted(() => searchFile());
// const filterSearch = () => {
//   let templateArr:Array<any> = [];
//   AllFileData.value.filter((item) => {
//     return item.name.indexOf(searchData) > -1;
//   }).forEach((item) => {
//     let isAll = true;
//     templateArr.forEach((items, index) => {
//       if (templateArr[index][item.type]) {
//         isAll = false;
//         templateArr[index][item.type].push(item);
//       }
//     });
//     if (isAll) {
//       templateArr.push({ [item.type]: [item] });
//     }
//   });
//   searchFileData.value = templateArr;

// }
const searchFile = () => {
  $axios.get("/pdf/search").then((res) => {
    let data = res.data;
    AllFileData.value = res.data.data;
    let templateArr: Array<templateArrItemType> = [];
    data.error === -1 &&
      data.data.forEach((item: pdfType) => {
        let isAll = true;
        templateArr.forEach((items, index: number) => {
          if (templateArr[index][item.type]) {
            isAll = false;
            templateArr[index][item.type].push(item);
          }
        });
        if (isAll) {
          templateArr.push({ [item.type]: [item] });
        }
      });
    searchFileData.value = templateArr;
  });
};
</script>

<style></style>
